#include <iostream>
#include <unordered_map>
#include <fstream>
#include <sstream>
using namespace std;
//实现ordered_map词频统计问题，看一看统计效率怎么样
struct Record{
    Record(string word,int frequent)
    :_word(word)
    ,_frequent(frequent)
    {

    }

    string _word;
    int _frequent;
};

class Dictionary{
public:
    void read(const string& filename){
        ifstream ifs(filename);
        string line;
        while(getline(ifs,line)){
            istringstream iss(line);
            string word;
            while(iss>>word){
                if(is_alpay(word)){++_dict[word]; 
            }
        }
    }
    }

    void stroe(const string & filename){
        ofstream ofs(filename);
        for(auto ele:_dict){
        ofs<<ele.first<<" "<<ele.second<<endl;
    }
    }
    bool is_alpay(const string & word){
        auto it1=word.begin();
        auto it2=word.end();
        while(it1!=it2){
            if(!isalpha(*it1)){
                return false;
            }
            ++it1;
        }
        return true;
    }
private:
    unordered_map<string,int> _dict;
};

void test(){
    Dictionary dic;
    dic.read("The_Holy_Bible.txt");
    dic.stroe("4.txt");
}
int main(int argc, char * argv[]){
    test();
    return 0;
}

